// pages/confirm/index.js
import {
  API,
  getUrl
} from '../../utils/api'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderData: {},
    msg: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const eventChannel = this.getOpenerEventChannel()
    if (Object.keys(eventChannel).length > 0)
      eventChannel.on('sendData', (data) => {
        this.setData({
          orderData: data,
        })
      })
  },
  submit() {
    let data = {
      "chestCircumference": this.data.orderData.chestCircumference,
      "classNumber": this.data.orderData.classNumber,
      "clothesLength": this.data.orderData.clothesLength,
      "grade": this.data.orderData.grade,
      "height": this.data.orderData.height?.replace('cm', ''),
      "hipWidth": this.data.orderData.hipWidth,
      "measure": this.data.orderData.measure,
      "model": this.data.orderData.model,
      "openid": this.data.orderData.openid,
      "outsideLength": this.data.orderData.outsideLength,
      "phoneNumber": this.data.orderData.phoneNumber,
      "schoolId": this.data.orderData.schoolInfo.schoolId,
      "schoolName": this.data.orderData.schoolInfo.schoolName,
      "sex": this.data.orderData.sex,
      "special": this.data.orderData.special,
      "studentName": this.data.orderData.studentName,
      "studentNumber": this.data.orderData.studentNumber,
      "waistWidth": this.data.orderData.waistWidth,
      "weight": this.data.orderData.weight?.replace('kg', '')
    };
    wx.request({
      url: getUrl(API.UNIFORM_ORDER),
      method: "POST",
      data: data,
      success: (res) => {
        let msg;
        if(res.data){
          if(res.data.msg.indexOf('成功')>-1){
            this.setData({
              msg: res.data.msg
            });
            return;
          }
          msg=res.data.msg;
        }
        this.setData({
          msg:msg||'提交失败请稍后再试'
        });
      }
    })
  },
  closeMsgDialog() {
    if(this.data.msg.indexOf('成功')>-1){
      wx.navigateBack({delta:10});
    }
    this.setData({
      msg: ''
    });
  }


})